package com.hotleproject.controller;

import com.hotleproject.pojo.Adminiope;
import com.hotleproject.service.AdminiOperaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

//洗地
@Controller
@RequestMapping("/users")
public class AdminiOperation {
    @Autowired
    private AdminiOperaService adminiOperaService;


    @RequestMapping("/findAdminiOpera")
    public String findAdminiOpera(HttpSession session, HttpServletResponse response, HttpServletRequest request, Model model) throws IOException {
//        String hotlename=session.getAttribute("adminis").toString();
        String spPage = request.getParameter("pageNumber");
        //设置每页条数
        int pageSize = 20;
        //页数
        int pageNo = 0;
        if (spPage == null) {
            pageNo = 1;
        } else {
            pageNo = Integer.valueOf(spPage);
            if (pageNo < 1) {
                pageNo = 1;
            }
        }
        //设置最大页数
        int totalCount = 0;
        int count =  this.adminiOperaService.getOpeCount();
        if (count > 0) {
            totalCount = count;
        }
        int maxPage = totalCount % pageSize == 0 ? 1 : totalCount / pageSize + 1;
        if (pageNo > maxPage) {
            pageNo = maxPage;
        }
        int tempPageNo = (pageNo - 1) * pageSize;


////        String hotlename = session.getAttribute("adminis").toString();
//        model.addAttribute("hotlename", hotlename);
//////        model.addAttribute("pageNo1", pageNo);
//        model.addAttribute("pageNo", tempPageNo);
//        model.addAttribute("pageSize", pageSize);
//        return "text";

        List<Adminiope> list=this.adminiOperaService.selectAllOpe(tempPageNo,pageSize);
//
//        //最后把信息放入model转发到页面把信息带过去
        model.addAttribute("list",list);
//        model.addAttribute("list",list);
        model.addAttribute("pageNo",pageNo);
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("maxPage",maxPage);
        return "AdminiOperation";

//        return "text";
    }
}
